//
//  PubicView.m
//  投融保
//
//  Created by admin on 14-1-7.
//  Copyright (c) 2014年 木叶科技. All rights reserved.
//

#import "PubicView.h"
#import "MYLoginViewController.h"
#import "proCell.h"
#import "proList.h"
#import "MYWebService.h"
#import "InvestmentContentViewController.h"
#import "SVPullToRefresh.h"
@interface PubicView ()<MBProgressHUDDelegate>{
    
    UITableView *proTableView;
    UIScrollView *topScroll;
    UIPageControl *pageControll;
    MBProgressHUD *mbHud;
    UIScrollView *contenScroll;
    NSInteger indexTag;
    int pageNo1;
    int pageNo2;
    int pageNo3;
    BOOL isNull1;
    BOOL isNull2;
    BOOL isNull3;
}

@end

@implementation PubicView
@synthesize mainView;
NSString *key;
NSMutableArray *proArray;
NSDictionary *loginDic;
NSMutableArray *ytProArray;
NSMutableArray *eduProArray;
float j;
bool isLogin;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
#pragma mark-   -----------状态栏底色------
- (UIStatusBarStyle)preferredStatusBarStyle
{
    [self.view setBackgroundColor:[UIColor blackColor]];
    return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
    return NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self initView];
    [self setPublic];
    isLogin = NO;
    isNull1=NO;
    isNull2=NO;
    isNull3=NO;
}
//程序启动之后 自动加载刷新新数据！
//-(void)viewDidAppear:(BOOL)animated{
//
//    [((UITableView *)[self.view viewWithTag:50]) triggerPullToRefresh];
//    [((UITableView *)[self.view viewWithTag:52]) triggerPullToRefresh];
//    [((UITableView *)[self.view viewWithTag:51]) triggerPullToRefresh];
//
//}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)setPublic{
    if (proArray==nil||ytProArray==nil||eduProArray==nil) {
        pageNo1 = 1;
        pageNo2 = 1;
        pageNo3 = 1;
    }else {
        pageNo1 = proArray.count/10;
        pageNo2 = ytProArray.count/10;
        pageNo3 = eduProArray.count/10;
    }
    
}
-(void)initView{
    int i = 0;
    int k = 0;
    if (SCREEN_HEIGHT>500) {
        k = 0;
    }else {
        k=20;
        
    }
    if (IOS_VERSION>=7.0) {
        i=0;
    }else {
        i=20;
    }
    float viWidth = self.view.frame.size.width;
    NSLog(@"viwidth%f",viWidth);
    topScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 105+i+k, viWidth, 173)];
    topScroll.contentSize = CGSizeMake(viWidth*3, 173);
    topScroll.pagingEnabled = YES;
    topScroll.bounces = NO;
    topScroll.tag = 10;
    topScroll.showsVerticalScrollIndicator = NO;
    topScroll.showsHorizontalScrollIndicator = NO;
    pageControll = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 105+173-30, viWidth, 17)];
    pageControll.currentPageIndicatorTintColor = [UIColor redColor];
    pageControll.numberOfPages = 3;
    //pageControll.tintColor = [UIColor whiteColor];
    [pageControll addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
    [mainView addSubview:topScroll];
    contenScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, k+i+173+105+105, viWidth, SCREEN_HEIGHT-383-k-i)];
    contenScroll.contentSize = CGSizeMake(viWidth*3, contenScroll.frame.size.height);
    contenScroll.pagingEnabled = YES;
    contenScroll.delegate = self;
    contenScroll.tag = 11;
    contenScroll.showsHorizontalScrollIndicator = YES;
    contenScroll.showsVerticalScrollIndicator = YES;
    __weak PubicView *weakSelf = self;
    for (int i = 0; i<3; i++) {
        UIImageView *topImageView = [[UIImageView alloc]initWithFrame:CGRectMake(viWidth*i, 0, viWidth, 173)];
        topImageView.image = [UIImage imageNamed:@"topImage"];
        [topScroll addSubview:topImageView];
        
        //加载三个tableviw
        proTableView = [[UITableView alloc]initWithFrame:CGRectMake(viWidth*i, 0, viWidth, contenScroll.frame.size.height)];
        proTableView.delegate=self;
        proTableView.dataSource=self;
        proTableView.showsHorizontalScrollIndicator = YES;
        proTableView.showsVerticalScrollIndicator = YES;
        proTableView.tag = 50+i;//tableTAG ==  50  51  52;
        proTableView.separatorStyle=NO;
        
        [proTableView addPullToRefreshWithActionHandler:^{
            [weakSelf insertRowAtTop];
        }];
        [proTableView addInfiniteScrollingWithActionHandler:^{
            [weakSelf insertRowAtBottom];
        }];
        [contenScroll addSubview:proTableView];
    }
    [self creatKey];
    [mainView addSubview:pageControll];
    
    // ------异步加载数据
    if (proArray==nil) {
        
        mbHud = [[MBProgressHUD alloc] initWithView:self.view];
        mbHud.labelText = @"正在加载";
        [self.view addSubview:mbHud];
        mbHud.delegate = self;
        [mbHud show:YES];
        //获取项目列表
        NSString *  strIndexTrade = [NSString stringWithFormat:@"service=indexTrade&tradeType=1&pageSize=10&pageNo=1"];
        [[MYWebService new]getDataAsynWithKey:key encryptedString:strIndexTrade appKey:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getdata:)   name:@"getAsyData" object:nil];
    }else{
        [(UITableView *)[self.view viewWithTag:50] reloadData];
        [(UITableView *)[self.view viewWithTag:51] reloadData];
        [(UITableView *)[self.view viewWithTag:52] reloadData];
        [mainView addSubview:contenScroll];
        
    }
    
    
}
-(void)insertRowAtTop{
    int64_t delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    //回到主线程更新数据，关闭动画
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        
        switch (indexTag) {
            case 0:{
                UITableView *firstTabl = (UITableView *)[self.view viewWithTag:50];
                NSString  *encrytedStr = @"service=indexTrade&tradeType=1&pageSize=10&pageNo=1";
                proArray =  [[JsonParse new] proListPerse:[[MYWebService new]getDataSynWithKey:key encryptedString:encrytedStr appKey:nil]];
                 [firstTabl reloadData];
                [firstTabl.pullToRefreshView stopAnimating];
            }
                NSLog(@"%d---",proArray.count);
                
                break;
            case 1:{
                NSString *encrytedStr = @"service=indexTrade&tradeType=1&pageSize=10&pageNo=1&guarantee=YT";
                ytProArray = [[JsonParse new] proListPerse:[[MYWebService new] getDataSynWithKey:key encryptedString:encrytedStr appKey:nil]];
                [(UITableView *)[self.view viewWithTag:51]reloadData];
                [((UITableView *)[self.view viewWithTag:51]).pullToRefreshView stopAnimating];
            }
                break;
            case 2:
            {
                NSString *encrytedStr = @"service=indexTrade&tradeType=1&pageSize=10&pageNo=1&guarantee=EDU";
                eduProArray = [[JsonParse new] proListPerse:[[MYWebService new] getDataSynWithKey:key encryptedString:encrytedStr appKey:nil]];
                [(UITableView *)[self.view viewWithTag:52]reloadData];
                [((UITableView *)[self.view viewWithTag:52]).pullToRefreshView stopAnimating];
            }
                break;
            default:
                break;
        }
        
        
    });
    
}
-(void)insertRowAtBottom{
    int64_t delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    //回到主线程更新数据，关闭动画
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        
        switch (indexTag) {
            case 0:{
              
                NSLog(@"uunfinsih%d",ytProArray.count);
                NSLog(@"uunfinsih%d",eduProArray.count);
                NSLog(@"uunfinsih%d",proArray.count);
                
                if (isNull1==NO) {
                    UITableView *firstTabl = (UITableView *)[self.view viewWithTag:50];
                    pageNo1++;
                    NSString  *encrytedStr = [NSString stringWithFormat:@"service=indexTrade&tradeType=1&pageSize=10&pageNo=%d",pageNo1];
                    NSDictionary *rsDic = [[MYWebService new]getDataSynWithKey:key encryptedString:encrytedStr appKey:nil];
                    NSMutableArray *moreArr =  [[JsonParse new] proListPerse:rsDic];
                    [proArray addObjectsFromArray:moreArr];
                    NSArray *rsArray = [NSArray new];
                    rsArray = [rsDic valueForKey:@"infos"];
                    if (rsArray.count<10) {
                        isNull2=YES;
                        [((UITableView *)[self.view viewWithTag:51]).infiniteScrollingView stopAnimating];
                        UIAlertView *proAlert = [[UIAlertView alloc]initWithTitle:nil message:@"数据已加载完" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                        [proAlert show];
                    }else {
                        [firstTabl reloadData];
                        [firstTabl.infiniteScrollingView stopAnimating];
                    }
                   
                }else {
                    [((UITableView *)[self.view viewWithTag:50]).infiniteScrollingView stopAnimating];
                    
                }
            }
                break;
            case 1:{
                NSLog(@"uunfinsih%d",ytProArray.count);
                NSLog(@"uunfinsih%d",eduProArray.count);
                NSLog(@"uunfinsih%d",proArray.count);
                
                if (isNull2==NO) {
                    UITableView *secondTabl = (UITableView *)[self.view viewWithTag:51];
                    pageNo2++;
                    NSString *encrytedStr = [NSString stringWithFormat:@"service=indexTrade&tradeType=1&pageSize=10&pageNo=%d&guarantee=%@",pageNo2,@"YT"];
                    NSDictionary *rsDic = [[MYWebService new]getDataSynWithKey:key encryptedString:encrytedStr appKey:nil];
                    NSMutableArray *moreArr =  [[JsonParse new] proListPerse:rsDic];
                    NSArray *rsArray = [NSArray new];
                    rsArray = [rsDic valueForKey:@"infos"];
                    [ytProArray addObjectsFromArray:moreArr];
                    [secondTabl reloadData];
                    if (rsArray.count<10) {
                        isNull2=YES;
                        [secondTabl.infiniteScrollingView stopAnimating];
                        UIAlertView *proAlert = [[UIAlertView alloc]initWithTitle:nil message:@"数据已加载完" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                        [proAlert show];
                    }else {
                        [secondTabl.infiniteScrollingView stopAnimating];
                    }
                }else if(isNull2 == YES){
                    [((UITableView *)[self.view viewWithTag:51]).infiniteScrollingView stopAnimating];
                }
            }
                break;
            case 2:
            {

                NSLog(@"uunfinsih%d",ytProArray.count);
                NSLog(@"uunfinsih%d",eduProArray.count);
                NSLog(@"uunfinsih%d",proArray.count);
                
                if (isNull3==NO) {
                    
                    UITableView *thirdTabl = (UITableView *)[self.view viewWithTag:52];
                    pageNo3++;
                    NSString *encrytedStr = [NSString stringWithFormat:@"service=indexTrade&tradeType=2&pageSize=10&pageNo=%d&guarantee=%@",pageNo3,@"EDU"];
                    NSDictionary *rsDic =[[MYWebService new]getDataSynWithKey:key encryptedString:encrytedStr appKey:nil];
                    NSMutableArray *moreArr =  [[JsonParse new] proListPerse:rsDic];
                    NSArray *rsArray = [moreArr valueForKey:@"infos"];
                    [eduProArray addObjectsFromArray:moreArr];
                    [thirdTabl reloadData];
                    if (rsArray.count<10) {
                        isNull3=YES;
                        [thirdTabl.infiniteScrollingView stopAnimating];
                        UIAlertView *proAlert = [[UIAlertView alloc]initWithTitle:nil message:@"数据已加载完" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                        [proAlert show];
                        
                    }else {

                        [thirdTabl.infiniteScrollingView stopAnimating];
                    }
                }else if(isNull3==YES){
                    [((UITableView *)[self.view viewWithTag:52]).infiniteScrollingView stopAnimating];
                    
                }
                
            }
                break;
            default:
                break;
        }
        
        
    });
}
-(void)getdata:(NSNotification *)asyData{
    
    if (asyData!=nil) {
        proArray = [[JsonParse new] proListPerse:[asyData object]];
        NSString *encrytedStr = @"service=indexTrade&tradeType=1&pageSize=10&pageNo=1&guarantee=YT";
        asyRequest = [MYWebService new];
        asyRequest.delegate = self;
        [asyRequest publicGetDataAsynWithKey:key encryptedString:encrytedStr appKey:nil];
        
        ytProArray = [[JsonParse new] proListPerse:[[MYWebService new] getDataSynWithKey:key encryptedString:encrytedStr appKey:nil]];
        NSString *encrytedStr2 = @"service=indexTrade&tradeType=1&pageSize=10&pageNo=1&guarantee=EDU";
        eduProArray = [[JsonParse new] proListPerse:[[MYWebService new] getDataSynWithKey:key encryptedString:encrytedStr2 appKey:nil]];
        [proTableView reloadData];
        [mainView addSubview:contenScroll];
        [mbHud removeFromSuperview];
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }else if (proArray==nil){
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"网络连接失败" message:@"请重新连接" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [myAlert show];
        [mbHud removeFromSuperview];
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
    
}
-(void)finishSuccessRequest:(NSDictionary *)asyData{
    asyRequest = [MYWebService new];
    asyRequest.delegate = self;
    NSString *encrytedStr2 = @"service=indexTrade&tradeType=1&pageSize=10&pageNo=1&guarantee=EDU";
    [asyRequest getProFinishAsynWithKey:key encryptedString:encrytedStr2 appKey:nil];
}
-(void)proFinishRequest:(NSDictionary *)asyData{


}
-(void)pageChanged:(id)sender{
    
    
}
- (IBAction)btnClick:(UIButton *)sender {
    
    switch (sender.tag) {
        case 1:
            [self presentViewController:[MYLoginViewController new] animated:NO completion:nil];
            break;
        case 2:{
            [(UIButton *)[self.view viewWithTag:2] setBackgroundImage:[UIImage imageNamed:@"shoye"] forState:UIControlStateNormal];
            [(UIButton *)[self.view viewWithTag:3] setBackgroundImage:nil forState:UIControlStateNormal];
            [(UIButton *)[self.view viewWithTag:4] setBackgroundImage:nil forState:UIControlStateNormal];
            [contenScroll setContentOffset:CGPointMake(self.view.frame.size.width*0, 0) animated:YES];
            
        }
            break;
        case 3:
        {
            
            [(UIButton *)[self.view viewWithTag:2] setBackgroundImage:nil forState:UIControlStateNormal];
            [(UIButton *)[self.view viewWithTag:3] setBackgroundImage:[UIImage imageNamed:@"shoye"] forState:UIControlStateNormal];
            [(UIButton *)[self.view viewWithTag:4] setBackgroundImage:nil forState:UIControlStateNormal];
            [contenScroll setContentOffset:CGPointMake(self.view.frame.size.width*1, 0) animated:YES];
            ;
        }
            break;
        case 4:
            [(UIButton *)[self.view viewWithTag:2] setBackgroundImage:nil forState:UIControlStateNormal];
            [(UIButton *)[self.view viewWithTag:3] setBackgroundImage:nil forState:UIControlStateNormal];
            [(UIButton *)[self.view viewWithTag:4] setBackgroundImage:[UIImage imageNamed:@"shoye"] forState:UIControlStateNormal];
            [contenScroll setContentOffset:CGPointMake(self.view.frame.size.width*2, 0) animated:YES];
            break;
        default:
            break;
    }
}
- (IBAction)valueChanged:(id)sender {
}
//生成随机16位字符 26 字母
-(void)creatKey{
    int NUMBER_OF_CHARS = 16;
    char data[NUMBER_OF_CHARS];
    for (int x=0;x<NUMBER_OF_CHARS;data[x++] = (char)('A' + (arc4random_uniform(26))));
    key =  [[NSString alloc] initWithBytes:data length:NUMBER_OF_CHARS encoding:NSUTF8StringEncoding];
    
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.tag==11) {
        indexTag = scrollView.contentOffset.x/320;
        NSLog(@"----------%d",indexTag);
    }
    
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (scrollView.tag==11) {
        
        NSInteger index= fabs(scrollView.contentOffset.x)/scrollView.frame.size.width;
        [pageControll setCurrentPage:index];
        switch (index) {
            case 0:
                [(UIButton *)[self.view viewWithTag:2] setBackgroundImage:[UIImage imageNamed:@"shoye"] forState:UIControlStateNormal];
                [(UIButton *)[self.view viewWithTag:3] setBackgroundImage:nil forState:UIControlStateNormal];
                [(UIButton *)[self.view viewWithTag:4] setBackgroundImage:nil forState:UIControlStateNormal];
                break;
            case 1:
                [(UIButton *)[self.view viewWithTag:2] setBackgroundImage:nil forState:UIControlStateNormal];
                [(UIButton *)[self.view viewWithTag:3] setBackgroundImage:[UIImage imageNamed:@"shoye"] forState:UIControlStateNormal];
                [(UIButton *)[self.view viewWithTag:4] setBackgroundImage:nil forState:UIControlStateNormal];
                
                break;
            case 2:
                [(UIButton *)[self.view viewWithTag:2] setBackgroundImage:nil forState:UIControlStateNormal];
                [(UIButton *)[self.view viewWithTag:3] setBackgroundImage:nil forState:UIControlStateNormal];
                [(UIButton *)[self.view viewWithTag:4] setBackgroundImage:[UIImage imageNamed:@"shoye"] forState:UIControlStateNormal];
                break;
                
            default:
                break;
        }
        
    }
}
#pragma mark - Table view data source

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    int row=0;
    switch (tableView.tag) {
        case 50:
            row = proArray.count;
            break;
        case 51:
            row = ytProArray.count;
            break;
        case 52:
            row = eduProArray.count;
            break;
            
        default:
            break;
    }
    return row;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [UITableViewCell new];
    
    static NSString *CellIdentifier = @"proCell";
    proCell *proCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (proCell == nil ) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"proCell" owner:self options:nil];
        proCell = [array objectAtIndex:0];
    }
    switch (tableView.tag) {
        case 50:{
            proCell.selectionStyle = UITableViewCellSelectionStyleNone;
            proCell.jinDuLable.text  = [[proArray objectAtIndex:indexPath.row] persontage];
            proCell.guaranteeLable.text = [[proArray objectAtIndex:indexPath.row] guaranteeName];
            proCell.xuQiuLable.text = [NSString stringWithFormat:@"%@元",[[proArray objectAtIndex:indexPath.row] tradeAmount]];
            proCell.proTitleLable.text = [NSString stringWithFormat:@"%@",[[proArray objectAtIndex:indexPath.row] tradeName]];
            
            proCell.creatTimeLable.text = [NSString stringWithFormat:@"%@",[[proArray objectAtIndex:indexPath.row] investStartTime]];
            proCell.deadTimeLable.text = [NSString stringWithFormat:@"%@",[[proArray objectAtIndex:indexPath.row] deadline]];
            proCell.timeLbale.text = [[proArray objectAtIndex:indexPath.row] timePeriod];
            
            proCell.yearRate.text = [NSString stringWithFormat:@"%@",[[proArray objectAtIndex:indexPath.row] tradeAnnualRate]];
            proCell.yiRongLable.text = [NSString stringWithFormat:@"%@元",[[proArray objectAtIndex:indexPath.row] tradeLoanedAmount]];
            proCell.haichaLable.text = [NSString stringWithFormat:@"%@元",[[proArray objectAtIndex:indexPath.row] requiredAmount]];
            NSString *str = proCell.jinDuLable.text;
            if ([[[proArray objectAtIndex:indexPath.row] tradeStatus] integerValue]==1) {
                proCell.stateLable.text = @"投资中";
            }else if ([[[proArray objectAtIndex:indexPath.row] tradeStatus] integerValue]==2){
                proCell.stateLable.text = @"已完成";
            }
            NSRange rang1 =  [str rangeOfString:@"%"];
            float i = [proCell.jinDuLable.text substringToIndex:rang1.location].floatValue ;
            [proCell.progress setProgress:i/100 animated:YES];
            cell =proCell;
        }
            break;
        case 51:{
            proCell.selectionStyle = UITableViewCellSelectionStyleNone;
            proCell.jinDuLable.text  = [[ytProArray objectAtIndex:indexPath.row] persontage];
            proCell.guaranteeLable.text = [[ytProArray objectAtIndex:indexPath.row] guaranteeName];
            proCell.xuQiuLable.text = [NSString stringWithFormat:@"%@元",[[ytProArray objectAtIndex:indexPath.row] tradeAmount]];
            proCell.proTitleLable.text = [NSString stringWithFormat:@"%@",[[ytProArray objectAtIndex:indexPath.row] tradeName]];
            
            proCell.creatTimeLable.text = [NSString stringWithFormat:@"%@",[[ytProArray objectAtIndex:indexPath.row] investStartTime]];
            proCell.deadTimeLable.text = [NSString stringWithFormat:@"%@",[[ytProArray objectAtIndex:indexPath.row] deadline]];
            proCell.timeLbale.text = [[ytProArray objectAtIndex:indexPath.row] timePeriod];
            proCell.haichaLable.text = [NSString stringWithFormat:@"%@",[[ytProArray objectAtIndex:indexPath.row] requiredAmount]];
            proCell.yiRongLable.text = [NSString stringWithFormat:@"%@",[[ytProArray objectAtIndex:indexPath.row] tradeLoanedAmount]];
            proCell.yearRate.text = [NSString stringWithFormat:@"%@",[[ytProArray objectAtIndex:indexPath.row] tradeAnnualRate]];
            proCell.yiRongLable.text = [NSString stringWithFormat:@"%@元",[[ytProArray objectAtIndex:indexPath.row] tradeLoanedAmount]];
            proCell.haichaLable.text = [NSString stringWithFormat:@"%@元",[[ytProArray objectAtIndex:indexPath.row] requiredAmount]];
            if ([[[ytProArray objectAtIndex:indexPath.row] tradeStatus] integerValue]==1) {
                proCell.stateLable.text = @"投资中";
            }else if ([[[ytProArray objectAtIndex:indexPath.row] tradeStatus] integerValue]==2){
                proCell.stateLable.text = @"已完成";
            }

            NSString *str = proCell.jinDuLable.text;
            NSRange rang1 =  [str rangeOfString:@"%"];
            float i = [proCell.jinDuLable.text substringToIndex:rang1.location].floatValue ;
            [proCell.progress setProgress:i/100 animated:YES];
            cell = proCell;
        }
            
            break;
        case 52:{
            
            proCell.selectionStyle = UITableViewCellSelectionStyleNone;
            proCell.jinDuLable.text  = [[eduProArray objectAtIndex:indexPath.row] persontage];
            proCell.guaranteeLable.text = [[eduProArray objectAtIndex:indexPath.row] guaranteeName];
            proCell.xuQiuLable.text = [NSString stringWithFormat:@"%@元",[[eduProArray objectAtIndex:indexPath.row] tradeAmount]];
            proCell.proTitleLable.text = [NSString stringWithFormat:@"%@",[[eduProArray objectAtIndex:indexPath.row] tradeName]];
            
            proCell.creatTimeLable.text = [NSString stringWithFormat:@"%@",[[eduProArray objectAtIndex:indexPath.row] investStartTime]];
            proCell.deadTimeLable.text = [NSString stringWithFormat:@"%@",[[eduProArray objectAtIndex:indexPath.row] deadline]];
            proCell.timeLbale.text = [[eduProArray objectAtIndex:indexPath.row] timePeriod];
            
            proCell.yearRate.text = [NSString stringWithFormat:@"%@",[[eduProArray objectAtIndex:indexPath.row] tradeAnnualRate]];
            proCell.yiRongLable.text = [NSString stringWithFormat:@"%@元",[[eduProArray objectAtIndex:indexPath.row] tradeLoanedAmount]];
            proCell.haichaLable.text = [NSString stringWithFormat:@"%@元",[[eduProArray objectAtIndex:indexPath.row] requiredAmount]];
            if ([[[eduProArray objectAtIndex:indexPath.row] tradeStatus] integerValue]==1) {
                proCell.stateLable.text = @"投资中";
            }else if ([[[eduProArray objectAtIndex:indexPath.row] tradeStatus] integerValue]==2){
                proCell.stateLable.text = @"已完成";
            }

            NSString *str = proCell.jinDuLable.text;
            NSRange rang1 =  [str rangeOfString:@"%"];
            float i = [proCell.jinDuLable.text substringToIndex:rang1.location].floatValue ;
            [proCell.progress setProgress:i/100 animated:YES];
            cell = proCell;
        }
            
            break;
            
        default:
            break;
    }
    
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 270;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *str = [[proArray objectAtIndex:indexPath.row] persontage];
    NSLog(@"%@",str);
    NSRange rang1 =  [str rangeOfString:@"%"];
    NSString *strIndexTradeDetail=[NSString stringWithFormat:@"service=indexTradeDetail&tradeId=%@&demandId=%@",[[proArray objectAtIndex:indexPath.row] tradeId],[[proArray objectAtIndex:indexPath.row] demandId]];
    j =[str substringToIndex:rang1.location].floatValue;
    NSLog(@"%f",j);
    [[MYWebService new]getDataAsynWithKey:key  encryptedString:strIndexTradeDetail appKey:nil];
    
    [self presentViewController:[InvestmentContentViewController new] animated:YES completion:nil];
    
}
@end
